﻿/*----------------------------------------------------------------
       // Copyright (C) 2008 安华顺通(北京)科技有限公司
       // 版权所有。 
       //
       // 文件名：BaseContextMenu.cs
       // 文件功能描述：所有右键菜单的基类，提供所有结点共用的菜单功能。
       //
       // 
       // 创建标识：杨波
       //
       // 修改标识：
       // 修改描述：
       //
       // 修改标识：
       // 修改描述：
//----------------------------------------------------------------*/

#region UsingStatements

using System;
using System.ComponentModel;
using System.Windows.Forms;
using RuleCode.WinFormsUI.Docking;

#endregion

namespace RuleCode.ObjectTree
{
    [ToolboxItem(false)]
    public partial class BaseContextMenu : UserControl
    {
        private ObjectTreeForm m_objectTree;

        public BaseContextMenu()
        {
            InitializeComponent();
        }

        //右键菜单的基类，现有功能为打开新窗口，属性
        //导出，查找和附加具体逻辑未写
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //e.GetType().
            //sender.GetType(). 
            //dockPanel.DocumentStyle = DocumentStyle.SystemMdi;
            //if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
            //{

            m_objectTree = new ObjectTreeForm(Util.SelectedNode);
            m_objectTree.TabText = Util.SelectedNode.Text;

            //m_objectTree.MdiParent = Util.MdiParent;
            //m_objectTree.ObjectInProp = ObjectInProp;
            if (Util.NewFormDisplayMode == NewFormDisplayMode.UserControl)
            {
                Util.NewWindowCount++;
                m_objectTree.Show(Util.DockPanel_Middle  );
                m_objectTree.Disposed += new EventHandler(m_objectTree_Disposed);
                Util.SplitContainer.Panel2Collapsed = false;
                if (Util.ContextMenuStrip_MiddleWin != null)
                {
                    m_objectTree.TabPageContextMenuStrip = Util.ContextMenuStrip_MiddleWin;
                    Util.CurrentMiddleObjectTreeForm = m_objectTree;
                }
            }
            else
            {
                m_objectTree.Show();
            }

            //}
            //else
            //{
            // if (m_objectTree == null)
            //{
            //m_objectTree = new ObjectTreeForm(null);
            //}
            //m_objectTree.ObjectInProp = ObjectInProp;
            //m_objectTree.Show(dockPanel);
            // }
        }

        void m_objectTree_Disposed(object sender, EventArgs e)
        {
            Util.NewWindowCount--;
            if (Util.NewWindowCount == 0)
            {
                if (Util.NewFormDisplayMode == NewFormDisplayMode.UserControl)
                {
                    Util.SplitContainer.Panel2Collapsed = true;
                }
            }

            //throw new NotImplementedException();
        }


        public ContextMenuStrip getContextMenuStrip()
        {
            return baseContextMenuStrip;
        }

        private void propertyStripMenuItem_Click(object sender, EventArgs e)
        {
            Util.IsShowProperty = true;
            Util.SetPropertyContent(Util.SelectedNode);
            Util.setPropertyWindow(Util.SelectedNode.Property);
        }
    }
}